home *** CD-ROM | disk | FTP | other *** search
/ Aminet 21 / Aminet 21 (1997)(GTI - Schatztruhe)[!][Oct 1997].iso / Aminet / comm / mail / YAMscripts.lha / ArchiveMsgs.rexx < prev    next >
OS/2 REXX Batch file  |  1997-06-24  |  3KB  |  127 lines

  1. /* ArchiveMsgs.rexx 1.1 14-Jun-97 by Kai Nikulainen
  2. **
  3. ** Archives messages with given string in the subject. 
  4. **
  5. ** Mail your comments and bug reports to knikulai@utu.fi */
  6.  
  7. options results
  8.  
  9. Arc='c:lha m'    /* Use this command to archive the messages */
  10. GroupSize=10    /* How many messages are archived in each group */
  11. Defpath='Work:' /* Default path for the file requester */
  12. AddDate='yes'    /* If yes, current date is added to the default archive name */
  13. DeleteThem='no'    /* Set to yes, if your archiver doesn't remove files and you want them*/
  14.         /* to be deleted*/
  15.  
  16. BadChars='*:/"?'
  17.  
  18.   gtxt='Enter search pattern for subjects?'
  19. gtitle='Select messages to be archived'
  20.  gbuts='_Ok|_Exit script'
  21.  gtags='rt_pubscrname=YAMSCREEN'  /* Change here the name of the screen YAM runs */
  22.  
  23.  reqtxt='Do you want to archive these messages?'
  24. reqbuts='_Yes|_No|_Exit script'
  25.  
  26. call addlib('rexxreqtools.library',0,-30,0)
  27.  
  28. address 'YAM'
  29. 'GetFolderInfo Max'    /* How many messages are there? */
  30. n=result
  31.  
  32. 'GetFolderInfo Path'    /* Where is the folder */
  33. fp=result
  34. if pos(':',fp)=0 then fp='YAM:'fp
  35. if right(fp,1)~='/' & right(fp,1)~=':' then fp=fp'/'
  36.  
  37. 'GetFolderInfo Name'    /* What's it's name */
  38. arcname=result 
  39. if upper(AddDate)='YES' then arcname=arcname date()
  40. arcname=translate(arcname,'_',' ')        /* Translate spaces to _ */
  41. arcname=compress(arcname,BadChars)        /* Remove dangerous characters */
  42. arcname=rtfilerequest(DefPath,arcname,'Select archive name',,gtags)
  43. if arcname='' then exit
  44.  
  45. 'GetMailInfo Subject'
  46. pattern=result
  47. if upper(left(pattern,3))='RE:' then pattern=strip(substr(pattern,4))
  48. needle=upper(rtgetstring('*'pattern'*',gtxt,gtitle,gbuts,gtags))
  49. if needle='' then exit
  50.  
  51.  
  52. /* Let's open a window... */
  53. Call Close(STDOUT)
  54. Call Close(STDIN)
  55.  
  56. Call Open(STDOUT,'CON:1/11/600/180/ArchiveFolder.rexx Output/CLOSE/WAIT/SCREEN'scrn,'w')
  57. Call Pragma('*',STDOUT)
  58.  
  59. counter=0
  60. files=''
  61. say 'Following messages contain the string'
  62. do m=0 to n-1        /* Do for all messages in folder: */
  63.     'SetMail' m        /* Select a message */
  64.     'GetMailInfo File'    /* Get the filename */
  65.     file=result        /* Save the filename */
  66.     'GetMailInfo Subject'    /* Guess what it does now? */
  67.     subj=result
  68.     if match(needle,upper(subj)) then do    /* the string was found */
  69.         say subj
  70.         counter=counter+1
  71.         files=files || file || ' '
  72.         if counter=GroupSize then call Archive
  73.         end
  74.  
  75. end /* do m */
  76.  
  77. if counter>0 then call Archive
  78.  
  79. Say 'All messages have been examined.  You can close the window now.'
  80. 'MailUpdate'
  81. exit
  82.  
  83. Archive:
  84.     'Request "'reqtxt'" "'reqbuts'"'
  85.     if result=0 then exit
  86.     if result=1 then do
  87.         address command arc arcname files
  88.         if upper(DeleteThem)='YES' then address command 'delete' files 
  89.         end
  90.     counter=0
  91.     files=''
  92. return
  93.  
  94. Match: procedure
  95. parse arg pat,str
  96.     res=0
  97.     pat=upper(pat)
  98.     str=upper(str)
  99.     p1=pos('*',pat)
  100.     if p1=0 then
  101.         res=(pat=str)
  102.     else do
  103.         alku=left(pat,p1-1)    /* chars before first * */
  104.         ale=length(alku)
  105.         p2=lastpos('*',pat)
  106.         if left(str,ale)~=alku then
  107.             res=0
  108.         else 
  109.             if p1=length(pat) then 
  110.                 res=1
  111.             else do
  112.                 loppu=substr(pat,p1+1)
  113.                 p2=pos('*',loppu)
  114.                 if p2=0 then
  115.                     res=(right(str,length(loppu))=loppu)
  116.                 else do
  117.                     seur=left(loppu,p2-1)
  118.                     i=ale
  119.                     do while pos(seur,str,i+1)>0
  120.                         i=pos(seur,str,i+1)
  121.                         res=(res | Match(loppu,substr(str,i)))
  122.                         end
  123.                     end
  124.                 end /* else do */    
  125.             end
  126. return res
  127.